﻿using DAL;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BLL
{
    public class MemberBll
    {
        public MemberBll(MemberDal dal)
        {
            Dal = dal;
        }

        public MemberDal Dal { get; }

        /// <summary>
        /// 添加会员
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        public int AddMember(Member m)
        {
            try
            {
                int res = Dal.ChaName(m.Name);
                if (res > 0)
                {
                    return -1;
                }
                else
                {
                    int ress = Dal.ChaPhone(m.Phone);
                    if (ress > 0)
                    {
                        return -2;
                    }
                    else
                    {
                        return Dal.AddMember(m);
                    }
                }
               
            }
            catch (Exception)
            {

                throw;
            }
        }


        /// <summary>
        /// 显示查询
        /// </summary>
        /// <param name="Name"></param>
        /// <param name="Phone"></param>
        /// <returns></returns>
        public List<Member> ShowMember(string? Name , string? Phone )
        {
            try
            {
                List<Member> list = Dal.ShowMember(Name,Phone);
               
                return list;
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 逻辑单删
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int DeleteMember(int id)
        {
            try
            {
                int res =Dal.DeleteMember(id);
                if (res > 0)
                {
                    return 1;
                }
                else
                {
                    return -2;
                }
            }
            catch (Exception)
            {

                throw;
            }

        }
        /// <summary>
        /// 反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Member FanTian(int id)
        {
            try
            {
                return Dal.FanTian(id);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="m">属性</param>
        /// <returns></returns>
        public int UpdateMember(Member m)
        {
            try
            {
                int res=Dal.UpdateMember(m);
                if(res>0)
                {
                    return 1;
                }
                else
                {
                    return -2;
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
